package com.accenture.fd.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.accenture.fd.entity.DtoToSource;
import com.accenture.fd.utils.generator.model.ClassToExcelModel;

@Mapper
public interface DtoSourceDao {

	@Select("SELECT screen_id, class_id ,class_comment,parent_class,interface_class,name_kanji,name_physics,field_type FROM TB00011 where class_id = #{classId}")
	@Results({ @Result(property = "screenId", column = "screen_id"),
			@Result(property = "classId", column = "class_id"),
			@Result(property = "classComment", column = "class_comment"),
			@Result(property = "parentClass", column = "parent_class"),
			@Result(property = "interfaceClass", column = "interface_class"),
			@Result(property = "nameKanji", column = "name_kanji"),
			@Result(property = "namePhysics", column = "name_physics"),
			@Result(property = "fieldType", column = "field_type"), })
	List<DtoToSource> findById( @Param("classId") String classId);

	@Select("SELECT class_comment,parent_class,interface_class,name_kanji,name_physics FROM TB00011 where screen_id  = #{screenid} and class_id = #{classid}")
	@Results({ @Result(property = "fieldClassInfo", column = "class_comment"),
			@Result(property = "fieldImplClassNm", column = "parent_class"),
			@Result(property = "fieldInterface", column = "interface_class"),
			@Result(property = "fieldClassPhysicsNm", column = "name_physics"), })
	ClassToExcelModel getClassDesignModel(@Param("screenid") String screenid, @Param("classid") String designId);

	@Delete("DELETE FROM TB00011 WHERE screen_id  = #{screenid} and class_id = #{classId}")
	boolean deleteById(@Param("screenid") String screenid, @Param("classId") String classId);

	@Insert("INSERT INTO TB00011 (screen_id, class_id,parent_class,interface_class,name_kanji,name_physics,create_status) VALUES(#{screenId}, #{classId},#{parentClass},#{interfaceClass},#{nameKanji},#{namePhysics},#{createStatus})")
	void insert(DtoToSource dtoToSrc);

	@Delete("DELETE FROM TB00011 WHERE screen_id  = #{screenid}")
	void deleteByScreenIdId(String screenId);

	@Insert({
   	 "<script>",
   	 "insert into TB00011 value ",
   	 "<foreach collection='saveList' item='item' index='index' separator=','>",
   	 	"("+
   			 "#{item.screenId},"+
   			 "#{item.classId},"+
   		     "#{item.classComment},"+
   		     "#{item.parentClass},"+
   		     "#{item.interfaceClass},"+
   		     "#{item.nameKanji},"+
   		     "#{item.namePhysics},"+
   		     "#{item.createStatus},"+
   		     "#{item.fieldType})",
   	 "</foreach>",
   	 "</script>"
   	})
	void saveAll(@Param(value="saveList") List<DtoToSource> saveList);
}